package com.zyh.pool;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author zyh
 * @Date 2024/8/12 11:37
 * @Description newFixedThreadPool 线程池，可以自定义最大核心数量
 */

public class ThreadPoolDemo4 {
    public static void main(String[] args) {
        ThreadPoolExecutor threadPool=new ThreadPoolExecutor(3,3,0L, TimeUnit.MILLISECONDS,new LinkedBlockingDeque<Runnable>());
        //获取线程池的核心数量个数
        System.out.println("threadPool.getPoolSize() = " + threadPool.getPoolSize());
        for (int i=1;i<=1000;i++) {
            threadPool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName()+"正在执行");
                }
            });
        }
        threadPool.shutdown();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("threadPool.getPoolSize() = " + threadPool.getPoolSize());

    }
}
